package pay.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


@Component
public class WechatOtherConfig {

    @Value("${weixin.other.appId}")
    private String appId;

    @Value("${weixin.other.secret}")
    private String secret;

    @Value("${weixin.other.app_login_url}")
    private String appLoginUrl;

    /**
     * 获取微信登录URL
     *
     * @param code 微信授权码
     * @return 完整的登录URL
     */
    public String getAppLoginUrl(String code) {
        if (appLoginUrl == null || appId == null || secret == null) {
            throw new IllegalStateException("微信配置参数未正确初始化");
        }
        return String.format("%s?appid=%s&secret=%s&code=%s&grant_type=authorization_code",
                appLoginUrl, appId, secret, code);
    }
}

